package com.example.android.ui.personal;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.RequestBody;

public class PersonalPresenter implements PersonalContract.IPersonalPresenter {
    PersonalContract.IPersonalModel personalModel;
    private PersonalContract.IPersonalView personalView;
    public PersonalPresenter(PersonalContract.IPersonalView personalView){
        this.personalView = personalView;
        personalModel = new PersonalModel();
    }

    @Override
    public void setPersonalData(RequestBody body,String token) {
        personalModel.setPersonalData(body,token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean bool) throws Throwable {
                        System.out.println(bool);
                        personalView.setPersonalDateSuccess(bool);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        personalView.setPersonalDateError(throwable);
                    }
                });
    }
}
